<template>
  <div style="margin-top: 50px">
    <el-form
      :model="corporateCulture"
      ref="corporateCultureForm"
      label-width="150px"
      style="width: 720px"
      size="small"
    >
      <el-form-item label="顶部图片:">
        <single-upload v-model="corporateCulture.imgUrl"></single-upload>
      </el-form-item>
      <el-form-item label="驾校名称">
        <el-input
          v-model="corporateCulture.driverschoolName"
          class="input-width"
        ></el-input>
      </el-form-item>
      <el-form-item label="驾校地址">
        <el-input
          v-model="corporateCulture.driverschoolAddr"
          class="input-width"
        ></el-input>
      </el-form-item>
      <el-form-item label="驾校电话">
        <el-input
          v-model="corporateCulture.driverschoolPhone"
          class="input-width"
        ></el-input>
      </el-form-item>
      <el-form-item label="教练人数">
        <el-input
          v-model="corporateCulture.coachNum"
          class="input-width"
        ></el-input>
      </el-form-item>
      <el-form-item label="车辆数">
        <el-input
          v-model="corporateCulture.carNum"
          class="input-width"
        ></el-input>
      </el-form-item>
      <el-form-item label="驾校简介">
        <tinymce
          :width="595"
          :height="300"
          v-model="corporateCulture.cultureContent"
        ></tinymce>
      </el-form-item>
      <el-form-item style="text-align: center">
        <el-button
          type="primary"
          size="medium"
          @click="submitCorporateCulture('corporateCultureForm')"
          >保存</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
const defaultCorporateCulture = {
  imgUrl: "",
  cultureContent: "",
  driverschoolName: "",
  driverschoolAddr: "",
  driverschoolPhone: "",
  carNum: 0,
  coachNum: 0,
};
import SingleUpload from "@/components/Upload/singleUpload";
import Tinymce from "@/components/Tinymce";
import {
  fetch,
  createCorporateCulture,
  updateCorporateCulture,
} from "@/api/dms/corporateculture";
export default {
  name: "CorporateCultureDetail",
  components: { Tinymce, SingleUpload },
  data() {
    return {
      corporateCulture: {},
    };
  },
  created() {
    this.getCorporateCulture();
  },
  methods: {
    getCorporateCulture() {
      fetch().then((response) => {
        console.log(response.data);
        if (response.data) {
          this.corporateCulture = response.data;
        }
      });
    },
    submitCorporateCulture(formName) {
      if (this.corporateCulture.id) {
        updateCorporateCulture(
          this.corporateCulture.id,
          this.corporateCulture
        ).then((response) => {
          this.$refs[formName].resetFields();
          this.$message({
            message: "修改成功",
            type: "success",
            duration: 1000,
          });
        });
      } else {
        createCorporateCulture(this.corporateCulture).then((response) => {
          this.$refs[formName].resetFields();
          this.corporateCulture = Object.assign({}, defaultCorporateCulture);
          this.$message({
            message: "提交成功",
            type: "success",
            duration: 1000,
          });
        });
      }
    },
  },
};
</script>

<style scoped>
.littleMarginLeft {
  margin-left: 10px;
}

.littleMarginTop {
  margin-top: 10px;
}

.paramInput {
  width: 250px;
}

.paramInputLabel {
  display: inline-block;
  width: 100px;
  text-align: right;
  padding-right: 10px;
}

.cardBg {
  background: #f8f9fc;
}
</style>
